<template>
    <div>
        <el-form ref="form" :rules="rules" :model="form" label-width="auto">
            <el-form-item  label="姓名" prop="name">
                <el-input v-model="form.name" ref="name"
                          :placeholder="`请输入一个${$root.s_store.sex === '1' ? '男' : '女'}性化姓名`"></el-input>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
module.exports = {
    watch: {
        '$root.s_store.name': {
            immediate: true,
            handler(val) {
                this.form.name = val
            }
        },
        '$root.s_store.sex': {
            immediate: true,
            handler() {
                this.form.name = ''
            }
        },
        form: {
            deep: true,
            handler(val) {
                this.$emit('change', val)
            }
        }
    },
    created() {
        this.$nextTick(() => this.$refs['name'].focus())
    },
    data() {
        return {
            form: {
                name: ''
            },
            rules: {
                name: [
                    { required: true, message: '请输入姓名', trigger: 'blur' }
                ]
            }
        }
    },
    methods: {
        valid() {
            let result = false;
            this.$refs["form"].validate((valid, object) => {
                result = valid;
                let keys = Object.keys(object ?? {});
                if (keys.length > 0) {
                    this.$scrollCenter(this.$refs[keys[0]].$el)
                }

            })
            return result;
        }

    }
}
</script>

<style scoped>

</style>
